package fairygui.editor.utils
{
   import flash.filesystem.File;
   import flash.filesystem.FileMode;
   import flash.filesystem.FileStream;
   
   public class Logger
   {
      
      private static var _file:File;
       
      
      public function Logger()
      {
         super();
      }
      
      public static function print(param1:String) : void
      {
         var fileName:String = null;
         var appFolder:File = null;
         var logFolder:File = null;
         var msg:String = param1;
         var now:Date = new Date();
         if(!_file)
         {
            fileName = now.fullYear + "-" + now.month + "-" + now.date + ".log";
            appFolder = new File(new File(File.applicationDirectory.url).nativePath);
            logFolder = appFolder.resolvePath("logs");
            if(!logFolder.exists)
            {
               logFolder.createDirectory();
            }
            _file = logFolder.resolvePath(fileName);
         }
         var fs:FileStream = new FileStream();
         try
         {
            fs.open(_file,FileMode.APPEND);
            fs.writeUTFBytes("[" + now.toTimeString() + "] " + msg + "\r\n");
            fs.close();
            return;
         }
         catch(err:Error)
         {
            return;
         }
      }
   }
}
